package tool

import play.api.data.Form
import play.api.data.Forms._
import play.api.data.format.Formats.doubleFormat
import tool.Pojo._

/**
 * Created by yz on 6/5/2021
 */
object FormTool {

  val pageForm = Form(
    mapping(
      "limit" -> number,
      "offset" -> number,
      "search" -> optional(text),
    )(PageData.apply)(PageData.unapply)
  )

  val longForm = Form(
    mapping(
      "samples" -> optional(seq(text)),
      "samplesMethod" ->text,
      "geneType" -> text,
      "tissue" -> optional(text),
      "dfMin" -> optional(of(doubleFormat)),
      "dfMax" -> optional(of(doubleFormat)),
      "diffSamples" -> optional(seq(text)),
      "diffSamplesMethod" -> text,
      "order" -> text,
      "sort" -> optional(text),
    )(LongData.apply)(LongData.unapply)
  )

  val circRnaForm = Form(
    mapping(
      "chr" -> text,
      "circBase" -> text,
      "geneSymbol" -> text,
      "samples" -> optional(seq(text)),
      "samplesMethod" ->text,
      "start" -> optional(number),
      "end" -> optional(number),
      "dfMin" -> optional(of(doubleFormat)),
      "dfMax" -> optional(of(doubleFormat)),
      "diffSamples" -> optional(seq(text)),
      "diffSamplesMethod" -> text,
      "geneName" -> optional(text),
  "order" -> text,
  "sort" -> optional(text),
    )(CircRnaData.apply)(CircRnaData.unapply)
  )

  val pathwayForm = Form(
    mapping(
      "sources" -> optional(seq(text)),
      "diffSamples" -> optional(seq(text)),
      "diffSamplesMethod" -> text,
      "order" -> text,
      "sort" -> optional(text),
    )(PathwayData.apply)(PathwayData.unapply)
  )

  val cellForm = Form(
    mapping(
      "cellOrigins" -> optional(seq(text)),
      "cellTypes" -> optional(seq(text)),
      "diffSamples" -> optional(seq(text)),
      "diffSamplesMethod" -> text,
    )(CellData.apply)(CellData.unapply)
  )

  val geneSymbolForm = Form(
    mapping(
      "geneSymbol" -> text
    )(GeneSymbolData.apply)(GeneSymbolData.unapply)
  )

  val base64Form = Form(
    mapping(
      "base64" -> text
    )(Base64Data.apply)(Base64Data.unapply)
  )

  val imageTypeForm = Form(
    mapping(
      "imageType" -> text
    )(ImageTypeData.apply)(ImageTypeData.unapply)
  )

  val idForm = Form(
    mapping(
      "id" -> text
    )(IdData.apply)(IdData.unapply)
  )

  val idOpForm = Form(
    mapping(
      "id" -> optional(text)
    )(IdOpData.apply)(IdOpData.unapply)
  )

  val idsForm = Form(
    mapping(
      "ids" -> list(text)
    )(IdsData.apply)(IdsData.unapply)
  )

  val positionForm = Form(
    mapping(
      "chr" -> text,
      "start" -> number,
      "end" -> number,
    )(PositionData.apply)(PositionData.unapply)
  )

  val kindForm = Form(
    mapping(
      "kind" -> text
    )(KindData.apply)(KindData.unapply)
  )

  val kindOpForm = Form(
    mapping(
      "kind" -> optional(text)
    )(KindOpData.apply)(KindOpData.unapply)
  )

  val tabOpForm = Form(
    mapping(
      "tab" -> optional(text)
    )(TabOpData.apply)(TabOpData.unapply)
  )

  val profileForm = Form(
    mapping(
      "id"->text,
      "kinds" -> list(text),
      "logScale" -> text
    )(ProfileData.apply)(ProfileData.unapply)
  )

  val comparisonForm = Form(
    mapping(
      "id"->text,
      "kindA" -> text,
      "kindB" -> text,
      "method" -> text,
      "logScale" -> text
    )(ComparisonData.apply)(ComparisonData.unapply)
  )

  val proportionForm = Form(
    mapping(
      "kind" -> optional(text),
      "sample" -> optional(text)
    )(ProportionData.apply)(ProportionData.unapply)
  )

  val fileNameForm = Form(
    mapping(
      "fileName" -> text
    )(FileNameData.apply)(FileNameData.unapply)
  )


}
